extends Node3D

@export var rotation_speed : float = 1.1
@onready var aim_ray = $AimRay
@onready var cooldown_timer = $CooldownTimer
@onready var smoky_shot_audio = $SmokyShotAudio

var is_ready_to_fire = true

func _process(delta):
	if Input.is_action_pressed("turret_left"):
		rotate_y(rotation_speed * delta)
	if Input.is_action_pressed("turret_right"):
		rotate_y(-rotation_speed * delta)
	if Input.is_action_just_pressed("fire") and is_ready_to_fire:
		smoky_shot_audio.play()
		is_ready_to_fire = false
		cooldown_timer.start()
		if aim_ray.is_colliding():
			var target = aim_ray.get_collider()
			print("hit!!! ", target.position)


func _on_cooldown_timer_timeout():
	is_ready_to_fire = true
